<?php

App::uses('AppController', 'Controller');

/**
 * DataParamBs Controller
 *
 * @property DataParamB $DataParamB
 * @property PaginatorComponent $Paginator
 * @property SessionComponent $Session
 */
class DataParamBsController extends AppController {

          /**
           * Components
           *
           * @var array
           */
          public $components = array('Paginator', 'Session');
          public $uses = array("DataParamB", "AreaCode", "PinCode");

          /**
           * index method
           *
           * @return void
           */
          public function admin_index() {
                    if ($this->request->is(array('post'))) {
                              $data = $this->request->data['input-search'];
                              if (!empty($data)) {
                                        $condition = array('OR' => array('mr_code LIKE' => "%$data%", 'rr_no LIKE' => "%$data%", 'account_id' => "$data", 'pin_code LIKE' => "%$data%", 'stress LIKE' => "%$data%", 'area LIKE' => "%$data%", 'district LIKE' => "%$data%", 'phone_number LIKE' => "%$data%", 'full_name LIKE' => "%$data%", 'land_mark LIKE' => "%$data%"));
                                        $this->Paginator->settings = array(
                                            'conditions' => $condition
                                        );
                              }
                    }
                    $this->DataParamB->recursive = 0;
                    $this->set('dataPramaBs', $this->Paginator->paginate('DataParamB'));
          }

          /**
           * view method
           *
           * @throws NotFoundException
           * @param string $id
           * @return void
           */
          public function view($id = null) {
                    if (!$this->DataParamB->exists($id)) {
                              throw new NotFoundException(__('Invalid data prama b'));
                    }
                    $options = array('conditions' => array('DataParamB.' . $this->DataParamB->primaryKey => $id));
                    $this->set('dataPramaB', $this->DataParamB->find('first', $options));
          }

          /**
           * add method
           *
           * @return void
           */
          public function admin_add() {
                    if ($this->request->is('post')) {
                              $this->DataParamB->create();
                              if ($this->DataParamB->save($this->request->data)) {
                                        $this->Session->setFlash(__('The data prama b has been saved.'));
                                        return $this->redirect(array('action' => 'index'));
                              } else {
                                        $this->Session->setFlash(__('The data prama b could not be saved. Please, try again.'));
                              }
                    }
                    $this->loadModel('DataPrama');
                    $dataPrama = $this->DataPrama->find('list', array('fields' => array('id', 'sdo')));
                    $this->set(compact('dataPrama'));
          }

          /**
           * edit method
           *
           * @throws NotFoundException
           * @param string $id
           * @return void
           */
          public function admin_edit($id = null) {
                    if (!$this->DataParamB->exists($id)) {
                              throw new NotFoundException(__('Invalid data prama b'));
                    }
                    if ($this->request->is(array('post', 'put'))) {
                              if ($this->DataParamB->save($this->request->data)) {
                                        $this->Session->setFlash(__('The data prama b has been saved.'));
                                        return $this->redirect(array('action' => 'index'));
                              } else {
                                        $this->Session->setFlash(__('The data prama b could not be saved. Please, try again.'));
                              }
                    } else {
                              $options = array('conditions' => array('DataParamB.' . $this->DataParamB->primaryKey => $id));
                              $this->request->data = $this->DataParamB->find('first', $options);
                    }
                    $this->loadModel('DataPrama');
                    $dataPrama = $this->DataPrama->find('list', array('fields' => array('id', 'sdo')));
                    $this->set(compact('dataPrama'));
          }

          /**
           * delete method
           *
           * @throws NotFoundException
           * @param string $id
           * @return void
           */
          public function admin_delete($id = null) {
                    $this->DataParamB->id = $id;
                    if (!$this->DataParamB->exists()) {
                              throw new NotFoundException(__('Invalid data prama b'));
                    }
                    $this->request->allowMethod('post', 'delete', 'get');
                    if ($this->DataParamB->delete()) {
                              $this->Session->setFlash(__('The data prama b has been deleted.'));
                    } else {
                              $this->Session->setFlash(__('The data prama b could not be deleted. Please, try again.'));
                    }
                    return $this->redirect(array('action' => 'admin_index'));
          }

          public function admin_search() {
                    if ($this->request->is(array('post'))) {
                              // debug($this->request->data);
                              $isConditions = false;
                              $condition = array();
                              $custum_name = trim($this->request->data['custum_name']);
                              if (!empty($custum_name)) {
                                        $isConditions = true;
                                        $condition[] = array('full_name LIKE' => "%$custum_name%");
                              }
                              $longitude = trim($this->request->data['longitude']);
                              if (!empty($longitude)) {
                                        $isConditions = true;
                                        $condition[] = array('long_titude LIKE ' => "%$longitude%");
                              }
                              $latitude = trim($this->request->data['latitude']);
                              if (!empty($latitude)) {
                                        $isConditions = true;
                                        $condition[] = array('lat_titude LIKE ' => "%$latitude%");
                              }
                              $rr_number = trim($this->request->data['rr_number']);
                              if (!empty($rr_number)) {
                                        $isConditions = true;
                                        $condition[] = array('rr_no' => "$rr_number");
                              }
                              $account_id = trim($this->request->data['account_id']);
                              if (!empty($account_id)) {
                                        $isConditions = true;
                                        $condition[] = array('account_id ' => "$account_id");
                              }
                              // $pole_id =trim($this->request->data['pole_id']);
                              /*  if(!empty($pole_id))
                                {
                                $isConditions=true;
                                $condition[]=array(''=>"$pole_id");
                                } */
                              $phone_number = trim($this->request->data['phone_number']);
                              if (!empty($phone_number)) {
                                        $isConditions = true;
                                        $condition[] = array('phone_number' => "$phone_number");
                              }
                              $area = trim($this->request->data['area']);
                              if (!empty($area)) {
                                        $isConditions = true;
                                        $condition[] = array('area LIKE' => "%$area%");
                              }
                              $landmark = trim($this->request->data['landmark']);
                              if (!empty($landmark)) {
                                        $isConditions = true;
                                        $condition[] = array('land_mark LIKE' => "%$landmark%");
                              }
                              $pin_code = trim($this->request->data['pin_code']);
                              if (!empty($pin_code)) {
                                        $isConditions = true;
                                        $condition[] = array('pin_code ' => "$pin_code");
                              }
                              $network_operation = trim($this->request->data['network_operation']);
                              if (!empty($network_operation)) {
                                        $isConditions = true;
                                        $condition[] = array('network_operator ' => "$network_operation");
                              }
                              if ($isConditions) {
                                        //   $condition = array('OR'=>array('mr_code LIKE'=>"%$data%",'rr_no LIKE'=>"%$data%",'account_id'=>"$data",'pin_code LIKE'=>"%$data%",'stress LIKE'=>"%$data%",'area LIKE'=>"%$data%",'district LIKE'=>"%$data%",'phone_number LIKE'=>"%$data%",'full_name LIKE'=>"%$data%",'land_mark LIKE'=>"%$data%"));

                                        $this->Paginator->settings = array(
                                            'conditions' => $condition
                                        );
                              }
                             
                              $this->set(compact('custum_name','network_operation','pin_code','landmark','phone_number','area','account_id','rr_number','longitude','latitude'));
                    }
                    $this->DataParamB->recursive = 0;
                    $dataPramaBs = $this->Paginator->paginate('DataParamB');
                    $areas = $this->AreaCode->find("all");
                    $pincodes = $this->PinCode->find("all");
                    $this->set(compact("areas", "pincodes"));
                    $this->set('dataPramaBs', $dataPramaBs);
                   //     $log = $this->DataParamB->getDataSource()->getLog(false, false);
                 //  debug($log);
          }

          public function admin_sms() {
                    if ($this->request->is(array('post'))) {
                              // debug($this->request->data);
                              $isConditions = false;
                              $condition = array();
                              $custum_name = trim($this->request->data['custum_name']);
                              if (!empty($custum_name)) {
                                        $isConditions = true;
                                        $condition[] = array('full_name LIKE' => "%$custum_name%");
                              }
                              $longitude = trim($this->request->data['longitude']);
                              if (!empty($longitude)) {
                                        $isConditions = true;
                                        $condition[] = array('long_titude LIKE ' => "%$longitude%");
                              }
                              $latitude = trim($this->request->data['latitude']);
                              if (!empty($latitude)) {
                                        $isConditions = true;
                                        $condition[] = array('lat_titude LIKE ' => "%$latitude%");
                              }
                              $rr_number = trim($this->request->data['rr_number']);
                              if (!empty($rr_number)) {
                                        $isConditions = true;
                                        $condition[] = array('rr_no' => "$rr_number");
                              }
                              $account_id = trim($this->request->data['account_id']);
                              if (!empty($account_id)) {
                                        $isConditions = true;
                                        $condition[] = array('account_id ' => "$account_id");
                              }
                              // $pole_id =trim($this->request->data['pole_id']);
                              /*  if(!empty($pole_id))
                                {
                                $isConditions=true;
                                $condition[]=array(''=>"$pole_id");
                                } */
                              $phone_number = trim($this->request->data['phone_number']);
                              if (!empty($phone_number)) {
                                        $isConditions = true;
                                        $condition[] = array('phone_number' => "$phone_number");
                              }
                              $area = trim($this->request->data['area']);
                              if (!empty($area)) {
                                        $isConditions = true;
                                        $condition[] = array('area LIKE' => "%$area%");
                              }
                              $landmark = trim($this->request->data['landmark']);
                              if (!empty($landmark)) {
                                        $isConditions = true;
                                        $condition[] = array('land_mark LIKE' => "%$landmark%");
                              }
                              $pin_code = trim($this->request->data['pin_code']);
                              if (!empty($pin_code)) {
                                        $isConditions = true;
                                        $condition[] = array('pin_code ' => "$pin_code");
                              }
                              $network_operation = trim($this->request->data['network_operation']);
                              if (!empty($network_operation)) {
                                        $isConditions = true;
                                        $condition[] = array('network_operator ' => "$network_operation");
                              }
                              if ($isConditions) {
                                        //   $condition = array('OR'=>array('mr_code LIKE'=>"%$data%",'rr_no LIKE'=>"%$data%",'account_id'=>"$data",'pin_code LIKE'=>"%$data%",'stress LIKE'=>"%$data%",'area LIKE'=>"%$data%",'district LIKE'=>"%$data%",'phone_number LIKE'=>"%$data%",'full_name LIKE'=>"%$data%",'land_mark LIKE'=>"%$data%"));

                                        $this->Paginator->settings = array(
                                            'conditions' => $condition
                                        );
                              
                                        
                              }
                               $this->set(compact('custum_name','network_operation','pin_code','landmark','phone_number','area','account_id','rr_number','longitude','latitude'));
                              $this->DataParamB->recursive = 0;
                              $dataPramaBs = $this->Paginator->paginate('DataParamB');
                              $this->set('dataPramaBs', $dataPramaBs);
                    }

                    // $log = $this->DataParamB->getDataSource()->getLog(false, false);
                    //debug($log);
                    $areas = $this->AreaCode->find("all");
                    $pincodes = $this->PinCode->find("all");
                    $this->set(compact("areas", "pincodes"));
          }

}
